package rickyGame.server.state
{
	import ricky.utils.TimeServer;
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	
	/**
	 * 
	 * 定时按间隔执行一个act
	 * 注意此act的lockedupComplete要设置成=true;
	 */
	public class InteravalAct extends Act2D
	{
		public function InteravalAct(act:Act2D,continueTime:Number,interval:Number)
		{
			_interval=interval;
			_continueTime=continueTime;
			_act=act;
		}
		
		/**
		 * 
		 */
		override public function begin():void
		{
			_startTime=TimeServer.now();
			_endTime=_startTime+_continueTime;
			_last=_startTime;
			_state=1;
		}
		
		override public function action(timeline:Number):void
		{
			if(_state<1)
				return;
			
			var dt:Number=timeline-_last;
			if(dt>= _interval)//
			{
				_last=timeline;
				_act.begin();
			}
			
			if(timeline>=_endTime)
			{
				_act.lockedupComplete=false;
				_act.complete();
				this.complete();
			}
		}
		
		//private 
		private var _act:Act2D;
		protected var _last:Number; //上次执行时间
		protected var _interval:int;//执行间隔		
		protected var _continueTime:Number;//持续时间
		private var _startTime:Number;//开始时间毫秒数
		private var _endTime:Number;//持续时间毫秒数
	}
}